
//获取类名的兼容函数
function getClass(classname,obj){
	var obj=obj||document;
	var arr=[];
	if(obj.getElementsByClassName){
		return obj.getElementsByClassName(classname);	
	}else{
		var all=document.getElementsByTagName("*");
		for(var i=0;i<all.length;i++){
			if(checkClass(all[i].className,classname)){
				arr.push(all[i])	
			};	
		};	
		return arr;
	};	
};
	//获取类名下的 检查一个标签多个类名拆分后的类名是否与传入的值相同
function checkClass(startclass,endclass){
	var arr=startclass.split(" ");
	for(var i=0;i<arr.length;i++){
		if(arr[i]==endclass){
			return true;	
		};	
	};	
	return false;
}

//获取文本内容的兼容函数
function getText(obj,val){
	if(document.all){
		if(val){
			obj.innerText=val
		}else{
			return obj.innerText;
		}
	}else{
		if(val){
			obj.textContent=val;	
		}else{
			return obj.textContent;	
		}
	}	
};



//获取样式
/*
obj  要获取的对象
attr 要获取的对象属性
*/
function getStyle(obj,attr){
	if(document.all){
		return obj.currentStyle[attr];	
	}else{
		return getComputedStyle(obj,null)[attr];	
	};	
};




//简单小动画
function animate(obj,attr,end,speed,callback){
	clearInterval(obj.time)
	var start=parseInt(getStyle(obj,attr));
	var flag=start<end?true:false;
	obj.time=setInterval(function(){
		if(flag){
			start+=speed;
			if(start>end){
				clearInterval(obj.time)	
				if(callback){
					callback();	
				}
			}else{
				obj.style[attr]=start+'px';	
			}
		}else{
			start-=speed;
			if(start<end){
				clearInterval(obj.time)	
				if(callback){
					callback();	
				}
			}else{
				obj.style[attr]=start+'px';	
			}
		}
	},80)	
};

//获取所有子元素
function getChilds(obj){
	var childs=obj.childNodes;
	var arr=[];
	for(var i=0;i<childs.length;i++){
		if(childs[i].nodeType==3){
			continue;	
		}else{
			arr.push(childs[i])	
		}
	};	
	return arr;
};
//获取第一个子元素
function getFirst(obj){
	var first=obj.firstChild;
	if(first==null){
		return false;	
	};	
	while(first.nodeType==3){
		first=first.nextSibling;
		if(first==null){
			return false;	
		};	
	};
	return first;
};
//获取最后一个子元素
function getLast(obj){
	var last=obj.lastChild;
	if(last==null){
		return false;	
	};
	while(last.nodeType==3){
		last=last.previousSibling;
		if(last==null){
			return false;	
		};	
	};
	return last;
};

//获取下一个兄弟节点
function getNext(obj){
	var next=obj.nextSibling;
	if(next==null){
		return false;	
	};	
	
	while(next.nodeType==3){
		next=next.nextSibling;
		if(next==null){
			return false;	
		};	
	};
	return next;
};

//获取上一个兄弟节点
function getPre(obj){
	var pre=obj.previousSibling;
	if(pre==null){
		return false;	
	};	
	
	while(pre.nodeType==3){
		pre=pre.previousSibling;
		if(pre==null){
			return false;	
		};	
	};
	return pre;
};

//插入到某个元素的后面
function insertAfter(parent,obj,newobj){
	var next=getNext(obj);
	if(next){
		parent.insertBefore(newobj,next)	
	}else{
		parent.appendChild(newobj)	
	}	
};
 //添加多个事件
 function addEvent (obj,ev,fn) {
  if(obj.attachEvent){
    obj.attachEvent("on"+ev,function  () {
	   fn.call(obj);
    });
  }else{
   obj.addEventListener(ev,fn,false);
  }
}
 //添加多个事件
function addEvent (obj,ev,fn) {
if(obj.attachEvent){
	obj.attachEvent("on"+ev,function  () {
	   fn.call(obj);
	});
	}else{
		obj.addEventListener(ev,fn,false);
	}
}

//删除事件
function delEvent (obj,ev,fn) {
	if(obj.removeEventListener){
		obj.removeEventListener(ev,fn,false) 
	}else{
	 alert("aa");
		 obj.detachEvent("on"+ev,fn) 
	}
}

//鼠标滚轮事件
function mouseScroll(obj,upfn,downfn){
	if(obj.attachEvent){
		obj.attachEvent('onmousewheel',scrollFn);	//IE、opera	
	}else if(obj.addEventListener){
		obj.addEventListener('mousewheel',scrollFn,false)	//chrome,safari
		obj.addEventListener('DOMMouseScroll',scrollFn,false)	//FF	
};	


	function scrollFn(e){
		var ev=e||event;
		//alert(ev.wheelDelta);		//IE
		//alert(ev.detail)		//FF
		var num=ev.detail||ev.wheelDelta;
		if(num==120||num==-3){	//为向上滚动
			if(upfn){
				upfn.call(obj);	
			}
		}else if(num==-120||num==3){	//为向下滚动
			if(downfn){
				downfn.call(obj)	
			}	
		};
		if(ev.preventDefault){
			ev.preventDefault();	//阻止默认浏览器动作（W3C）	
		}else{
			ev.returnValue=false;	//IE中附上函数默认动作的方式	
		}	
	};
}

//判断某个元素是否包含有另外一个元素
 function contains (parent,child) {
	if(parent.contains){
	   return parent.contains(child) && parent!=child;
	}else{
	  return (parent.compareDocumentPosition(child)===20);
	}
 }

//判断鼠标是否真正的从外部移入，或者是真正的移出到外部；
  function checkHover (e,target) {
	 if(getEvent(e).type=="mouseover"){
	    return !contains(target,getEvent(e).relatedTarget || getEvent(e).fromElement)&&
		!((getEvent(e).relatedTarget || getEvent(e).fromElement)===target)
	 }else{
		return !contains(target,getEvent(e).relatedTarget || getEvent(e).toElement)&&
		!((getEvent(e).relatedTarget || getEvent(e).toElement)===target)
		}
  }

//获得事件对象
  function getEvent (e) {
	    return e||window.event;
  }

  /*
  obj   要操作的对象
  overfun   鼠标移入需要处理的函数
  outfun     鼠标移除需要处理的函数
*/
function hover (obj,overfun,outfun) {
	  if(overfun){
	    obj.onmouseover=function  (e) {
			  if(checkHover(e,obj)){
			     overfun.call(obj);
			  }
	    }
	  }
	  if(outfun){
	    obj.onmouseout=function  (e) {
			  if(checkHover(e,obj)){
			     outfun.call(obj);
			  }
	    }
	  }
}


//拖拽
function drag(obj){
	obj.onmousedown=function(e){
		var ev=e||event;
		var ox=ev.clientX-obj.offsetLeft;
		var oy=ev.clientY-obj.offsetTop;	
		document.onmousemove=function(e){
			var ev=e||event;
			var cx=ev.clientX;
			var cy=ev.clientY;
			obj.style.left=cx-ox+'px';
			obj.style.top=cy-oy+'px';	
		};
		document.onmouseup=function(){
			document.onmousemove=null;
			if(this.releaseCapture){
				this.releaseCapture();	
			};	
		};
		if(this.setCapture){
			this.setCapture();	
		}
		return false;
		
	};	
};

//缩放
function zooms(obj,scrobj){
	obj.onmousedown=function(e){
		var ev=e||event;
		var ox=ev.clientX-obj.offsetLeft;
		var oy=ev.clientY-obj.offsetTop;	
		document.onmousemove=function(e){
			var ev=e||event;
			var cx=ev.clientX;
			var cy=ev.clientY;
			scrobj.style.width=cx-ox+'px';
			scrobj.style.height=cy-oy+'px';
			obj.style.left=scrobj.offsetWidth-obj.offsetWidth+'px';
			obj.style.top=scrobj.offsetHeight-obj.offsetHeight+'px';
		};
		document.onmouseup=function(){
			document.onmousemove=null;
			if(this.releaseCapture){
				this.releaseCapture();	
			};	
		};
		if(this.setCapture){
			this.setCapture();	
		}
		return false;
		
	};	
};